using System;
using NHibernate.Criterion;
using Rhino.Commons;
using Rhino.Security.Interfaces;
using WineCellar.Business.Entities;

namespace WineCellar.Business.SecurityInterfaces
{
    public class WineEntityInformationExtractor<T> :IEntityInformationExtractor<T> where T:Wine
    {
        private readonly IRepository<T> wineRepository;

        public WineEntityInformationExtractor(IRepository<T> wineRepository)
        {
            this.wineRepository = wineRepository;
        }

        public Guid GetSecurityKeyFor(T entity)
        {
            return entity.SecurityKey;
        }

        public string GetDescription(Guid securityKey)
        {
            var wine = wineRepository.FindOne(Expression.Eq("SecurityKey", securityKey));
            return string.Format("Wine: {0}", wine.Name);
        }

        public string SecurityKeyPropertyName
        {
            get { return "SecurityKey"; }
        }
    }
}